package com.bcx.crm.service.templateTestService;

import com.bcx.crm.entity.Template;
import com.bcx.crm.mapper.templateTestMapper.InsertTemplateMapper;
import com.bcx.crm.mapper.templateTestMapper.SelectTemplateMapper;
import com.bcx.crm.plat.core.utils.SpringContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ys on 2018/2/1.
 */
@Service
public class InsertTemplateService {
    private static final Map<String,Object> map = new HashMap<>();
    @Transactional(propagation = Propagation.REQUIRES_NEW,isolation = Isolation.READ_COMMITTED,
                    readOnly = true,timeout = 5)
    public int insertTemplate(Map<String,Object> param){return 1;}
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public int insertTemplate(){
        InsertTemplateMapper insertTemplateMapper = SpringContextHolder.getBean("insertTemplateMapper");
        int i = insertTemplateMapper.insertTemplate1(createMap());
        this.getTemplateById();
        if (i>0)
        throw new IllegalStateException("为了回滚而手动抛出异常");
//            throw new RuntimeException("为了回滚而手动抛出异常");
        return 1;
    }
    @Transactional(isolation = Isolation.SERIALIZABLE)
    private void getTemplateById(){
        SelectTemplateMapper selectTemplateMapper = SpringContextHolder.getBean(SelectTemplateMapper.class);
        map.put("row_id","rowId-----");
        List<Template> list1 = selectTemplateMapper.getList1(map);
    }
    public static Map<String,Object> createMap(){
        Map<String,Object> map = new HashMap<>();
        map.put("rowId","rowId-----");
        map.put("templateCode","templateCode-----");
        map.put("templateName","templateName-----");
        map.put("test","<li style=\"color: red\">ssssssssssssssssssssss</li>");
        return map;
    }
}
